package ru.pb.auth;

import org.apache.log4j.Logger;

import ru.pb.auth.auto_save.AuthShutdownThread;
import ru.pb.auth.controllers.AuthController;
import ru.pb.auth.data.AUTHLoader;
import ru.pb.auth.managers.IPManager;
import ru.pb.auth.network.ANetworkEngine;
import ru.pb.auth.network.threading.ThreadPoolManager;
import ru.pb.global.dao.DAOManager;
import ru.pb.global.dbc.DatabaseFactory;
import ru.pb.global.info.PrintInfo;
import ru.pb.global.logging.LoggingService;
import ru.pb.global.memory.GCTask;

/**
 * @author Felixx
 */
public class AuthServer
{
	private static final Logger _log = Logger.getLogger(AuthServer.class);

	public static void main(String... args) throws Exception
	{
		PrintInfo.getInstance();

		LoggingService.load();

		AUTHLoader.load();

		ThreadPoolManager.getInstance();

		PrintInfo.printLines("Init DataBase", "Begin");
		DatabaseFactory.getInstance();
		DAOManager.getInstance().load("auth");
		PrintInfo.printLines("Init DataBase", "End");
		PrintInfo.printEmptyLine();

		AuthController.load();
		IPManager.getInstance();

		PrintInfo.printLines("Init Nerwork engine", "Begin");
		ANetworkEngine.getInstance();
		PrintInfo.printLines("Init Nerwork engine", "End");
		PrintInfo.printEmptyLine();

		PrintInfo.printLibInfo(_log);
		PrintInfo.printEmptyLine();
		PrintInfo.getInstance().info();
		ThreadPoolManager.getInstance().scheduleAtFixedRate(new GCTask(), 60 * 1000 * 60, 60 * 1000 * 60); // gc() каждый час.
		Runtime.getRuntime().addShutdownHook(new AuthShutdownThread()); // Ловим трид остановки сервера.
	}
}